package com.ycxy.crm.workbench.web.controller;

import com.ycxy.crm.commons.contants.Contants;
import com.ycxy.crm.commons.domain.ReturnObject;
import com.ycxy.crm.commons.utils.DateUtils;
import com.ycxy.crm.commons.utils.UUIDUtils;
import com.ycxy.crm.settings.domain.User;
import com.ycxy.crm.workbench.domain.ClueRemark;
import com.ycxy.crm.workbench.service.ClueRemarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * @Author jayLuo
 * @Date 2022/10/8 19:43
 * @PackageName:com.ycxy.crm.workbench.web.controller
 * @ClassName: ClueRemarkController
 * @Description: TODO
 * @Version 1.0
 */
@Controller
public class ClueRemarkController {

    @Autowired
    ClueRemarkService clueRemarkService;

    @ResponseBody
    @RequestMapping("/workbench/clue/saveCreateClueRemark")
    public Object saveCreateClueRemark(ClueRemark remark, HttpSession session){
        User user = (User) session.getAttribute(Contants.SESSION_USER);
        //封装参数
        remark.setId(UUIDUtils.getUUID());
        remark.setCreateTime(DateUtils.formatDataTime(new Date()));
        remark.setCreateBy(user.getId());
        remark.setEditFlag(Contants.REMARK_EDIT_FLAG_NO_EDITED);
        ReturnObject returnObject = new ReturnObject();
        try {
            //调用service层方法,保存创建的市场活动备注
            int ret = clueRemarkService.saveClueRemark(remark);
            if (ret>0) {
                returnObject.setCode(Contants.RETURN_OBJECT_CODE_SUCCESS);
                returnObject.setRetData(remark);
            }else {
                returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
                returnObject.setMessage("系统忙,请稍后重试......");
            }
        } catch (Exception e) {
            e.printStackTrace();
            returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
            returnObject.setMessage("系统忙,请稍后重试......");
        }
        return returnObject;
    }

    @ResponseBody
    @RequestMapping("/workbench/clue/deleteClueRemarkById.do")
    public Object deleteClueRemarkById(String id){
        ReturnObject returnObject = new ReturnObject();
        //调用service层方法,删除备注
        try {
            //调用service层方法,保存创建的市场活动备注
            int ret = clueRemarkService.deleteClueRemarkById(id);
            if (ret>0) {
                returnObject.setCode(Contants.RETURN_OBJECT_CODE_SUCCESS);
            }else {
                returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
                returnObject.setMessage("系统忙,请稍后重试......");
            }
        } catch (Exception e) {
            e.printStackTrace();
            returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
            returnObject.setMessage("系统忙,请稍后重试......");
        }
        return returnObject;
    }

    @ResponseBody
    @RequestMapping("/workbench/clue/savaEditClueRemark.do")
    public Object savaEditClueRemark(ClueRemark remark,HttpSession session){
        User user = (User) session.getAttribute(Contants.SESSION_USER);
        //封装参数
        remark.setEditTime(DateUtils.formatDataTime(new Date()));
        remark.setEditBy(user.getId());
        remark.setEditFlag(Contants.REMARK_EDIT_FLAG_YES_EDITED);
        ReturnObject returnObject = new ReturnObject();
        try {
            //调用service层方法保存修改的市场活动备注
            int ret = clueRemarkService.updateClueRemark(remark);
            if (ret>0) {
                returnObject.setCode(Contants.RETURN_OBJECT_CODE_SUCCESS);
                returnObject.setRetData(remark);
            }else {
                returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
                returnObject.setMessage("系统忙,请稍后重试......");
            }
        } catch (Exception e) {
            e.printStackTrace();
            returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
            returnObject.setMessage("系统忙,请稍后重试......");
        }
        return returnObject;
    }

}
